package com.miracle9.game.dao;
import com.miracle9.game.entity.UserAward;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

@Repository
public class UserAwardServiceDao extends SqlOperating<UserAward, Integer>
{
  public void deleteByDate(String date)
  {
	  q_CreateSql("delete from UserAward where datetime like ?", new Object[] { date + "%" }).executeUpdate();
  }
  
  public int getSumGoldByDate(String date)
  {
    Query query = q_CreateSql("select sum(gold) from UserAward where datetime like ?", new Object[] { date + "%" });
    Object sum = query.uniqueResult();
    if (sum == null) {
      return 0;
    }
    return ((Number)sum).intValue();
  }
  
  public void deletePastAward(String date)
  {
	  q_CreateSql("delete from UserAward where datetime<?", new Object[] { date }).executeUpdate();
  }
  
  public int getSumGoldByInterval(String startDate, String endDate)
  {
    Object count = q_CreateSql("select sum(gold) from UserAward where datetime>=? and datetime<?", new Object[] { startDate, 
      endDate }).uniqueResult();
    if (count == null) {
      return 0;
    }
    return Integer.parseInt(count.toString());
  }
}
